<?php
namespace app\decorate\model;
use app\BaseModel;
use think\facade\Db;



class AdminStaffSite extends BaseModel
{
    //定义表名 风格表
    protected $name = 'longbing_card_decorate_staff_site';

    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }

    /**
     * User: chenniang
     * Date: 2019-10-12 09:54
     * @param $dis
     * @return mixed
     * descption:查询风格
     */
    public function styleSelect($dis){
        $data = $this->where($dis)->status(-1)->order('sort desc')->select()->toArray();
        return $data;
    }

    /**
     * @param $data
     * @return int|string
     * 添加风格
     */
    public function dataAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }


    /**
     * User: chenniang
     * Date: 2019-10-23 11:57
     * @param $site
     * @param $staff
     * @return void
     * descption:更新数据
     */

    public function changeData($site,$staff, $uniacid = 7777){
        $this->where(['site_id'=>$site])->where('staff_id','not in',$staff)->delete();
        if(!empty($staff)){
            foreach ($staff as $v){
                $data = $this->dataInfo(['site_id'=>$site,'staff_id'=>$v]);
                if(empty($data)){
                    $this->dataAdd(['site_id'=>$site,'staff_id'=>$v, 'uniacid' => $uniacid]);

                }
            }
        }
        return true;
    }

    /**
     * @param $dis
     * @return AdminCate
     * 风格详情
     */
    public function dataInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }




}